package com.sg.service.biz.bff.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.BffGenerateBackPrefabricateMsgContentReqDto;
import com.sg.dto.biz.bff.res.BffGenerateBackPrefabricateMsgContentRespDto;
import com.sg.dto.integration.component.GenerateSemanticInstanceStoryComReqDto;
import com.sg.dto.integration.component.GenerateSemanticInstanceStoryComRespDto;
import com.sg.dto.integration.component.QueryConfItemMatchAnswerDetailComReqDto;
import com.sg.dto.integration.component.QueryConfItemMatchAnswerDetailComRespDto;
import com.sg.dto.integration.framework.QueryUserInfoDetailComReqDto;
import com.sg.dto.integration.framework.QueryUserInfoDetailComRespDto;
import com.sg.service.biz.bff.TemplateEngineService;
import com.sg.common.exception.Assert;
import com.wicket.okrcomponent.integration.ConfSchemeService;
import com.wicket.okrcomponent.integration.TemplateEngineService;
import com.wicket.okrframework.integration.UserService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class TemplateEngineServiceImpl implements TemplateEngineService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    com.sg.service.biz.component.ConfSchemeService fwCompConfSchemeClient;

    @Resource
    com.sg.service.biz.framework.UserService fwBaseUserClient;

    @Resource
    com.sg.service.biz.component.TemplateEngineService fwCompTemplateEngineClient;

    /**
     * B2生成回退预制消息内容[8497]
     * gen by moon at 2/17/2024, 10:59:02 PM
     */
    @Trace(operationName = "B2生成回退预制消息内容")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffGenerateBackPrefabricateMsgContentRespDto generateBackPrefabricateMsgContent(BffGenerateBackPrefabricateMsgContentReqDto reqDto) {


        GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto_1 = null;
//步骤0: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
        QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto = null;
        QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto = new QueryConfItemMatchAnswerDetailComReqDto();
        queryConfItemMatchAnswerDetailComReqDto.setConfItemCode("MESSAGE_SENDER_CONF");//CUSTOM_CONVENTION//sourceId:1547181_1
        queryConfItemMatchAnswerDetailComReqDto.setConfSchemeCode("COM_CONF_SCHEME");//CUSTOM_CONVENTION//sourceId:1547182_1
        queryConfItemMatchAnswerDetailComReqDto.setIsPlatData("TRUE");//sourceId:1547183_1
        if (reqDto != null) {
            queryConfItemMatchAnswerDetailComReqDto.setConfOptionCode(reqDto.getSendMsgScene());//SimpleFieldAssign//sourceId:1551807_1
        }

        /*D2查平台发送消息场景匹配消息内容语义引擎模板答案[2486]   */
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfOptionCode(), "B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-选项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfItemCode(), "B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-配置项标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfSchemeCode(), "B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-配置方案标识不能为空", false);
        Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getIsPlatData(), "B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-是否标准答案不能为空", false);
        queryConfItemMatchAnswerDetailComRespDto = fwCompConfSchemeClient.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//步骤1: D1-2查询个人资料详情(公共) - queryUserInfoDetailCom
        QueryUserInfoDetailComRespDto queryUserInfoDetailComRespDto = null;
        QueryUserInfoDetailComReqDto queryUserInfoDetailComReqDto = new QueryUserInfoDetailComReqDto();
        queryUserInfoDetailComReqDto.setUserId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecUserId());//CURRENT_USERID//sourceId:1547200_1

        /*D1-2查当前用户真实姓名(用于生成消息内容入参)[408]   */
        Assert.isNull(queryUserInfoDetailComReqDto.getUserId(), "B2生成回退预制消息内容-D1-2查当前用户真实姓名(用于生成消息内容入参)-账号不能为空", false);
        queryUserInfoDetailComRespDto = fwBaseUserClient.queryUserInfoDetailCom(queryUserInfoDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


//步骤2: D2生成语义实例故事(公共) - generateSemanticInstanceStoryCom
        GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto = null;
        if (queryConfItemMatchAnswerDetailComRespDto != null) {
            GenerateSemanticInstanceStoryComReqDto generateSemanticInstanceStoryComReqDto = new GenerateSemanticInstanceStoryComReqDto();
            generateSemanticInstanceStoryComReqDto.setFirstFieldName("idCardName");//CUSTOM_CONVENTION//sourceId:1547150_1
            if (queryConfItemMatchAnswerDetailComRespDto != null) {
                generateSemanticInstanceStoryComReqDto.setTemplateSemanticEngineCode(queryConfItemMatchAnswerDetailComRespDto.getExtensionField2());//SimpleFieldAssign//sourceId:1547156_1
            }
            if (queryUserInfoDetailComRespDto != null) {
                generateSemanticInstanceStoryComReqDto.setFirstFieldValue(queryUserInfoDetailComRespDto.getIdCardName());//SimpleFieldAssign//sourceId:1547151_1
            }

            /*D2生成语义实例故事(公共)[8234]   */
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getTemplateSemanticEngineCode(), "B2生成回退预制消息内容-D2生成语义实例故事(公共)-模板引擎标识不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldName(), "B2生成回退预制消息内容-D2生成语义实例故事(公共)-第一个字段字段名不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldValue(), "B2生成回退预制消息内容-D2生成语义实例故事(公共)-第一个字段字段值不能为空", false);
            generateSemanticInstanceStoryComRespDto = fwCompTemplateEngineClient.generateSemanticInstanceStoryCom(generateSemanticInstanceStoryComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


            generateSemanticInstanceStoryComRespDto_1 = generateSemanticInstanceStoryComRespDto;
        }

        BffGenerateBackPrefabricateMsgContentRespDto retData = new BffGenerateBackPrefabricateMsgContentRespDto();
        if (generateSemanticInstanceStoryComRespDto_1 != null) {
            retData.setMessageContent(generateSemanticInstanceStoryComRespDto_1.getObjectName());//SimpleFieldAssign//sourceId:1547202_1
        }


        return retData;
    }
    //
}
